
/**
 * Please modify this class to meet your needs
 * This class is not complete
 */

package com.jy.rhin.facade.ws.document.retrieve;

import cn.org.chiss.rhin._2015.document.management.DocumentStoredQuery;
import cn.org.chiss.rhin._2015.document.management.DocumentStoredQueryResponse;
import cn.org.chiss.rhin._2015.document.repository.RetrieveDocumentSet;
import cn.org.chiss.rhin._2015.document.repository.RetrieveDocumentSetResponse;
import com.jy.framework.base.utils.Serializer;
import com.jy.rhin.config.NamespaceConstants;
import com.jy.rhin.config.ws.WsClientFactory;
import com.jy.rhin.facade.ws.document.management.DocumentManagement;
import com.jy.rhin.facade.ws.document.storage.DocumentStorage;
import com.jy.rhin.infra.exception.RhinAggrErrorType;
import com.jy.rhin.support.aspect.AuditLog;
import com.jy.rhin.support.util.Asserts;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.jws.WebService;

/**
 * This class was generated by Apache CXF 3.5.1
 * 2022-04-20T10:15:25.328+08:00
 * Generated source version: 3.5.1
 *
 * @author dhl
 */

@Slf4j
@WebService(
        serviceName = "DocumentRetrieveService",
        portName = "DocumentRetrievePort",
        targetNamespace = NamespaceConstants.NS_RHIN,
        endpointInterface = "com.jy.rhin.facade.ws.document.retrieve.DocumentRetrieve")
@Component
public class DocumentRetrievePortImpl implements DocumentRetrieve {

    @Resource
    WsClientFactory wsClientFactory;

    /**
     * 获取文档索引
     *
     * @param document
     * @return
     */
    @Override
    @AuditLog
    public RetrieveDocumentSetResponse retrieveDocumentSet(RetrieveDocumentSet document) {
        log.info("Executing operation retrieveDocumentSet:{}", Serializer.serialize(document));
        return queryDocumentIndex(document);
    }

    /**
     * 文档集获取
     *
     * @param message
     * @return
     */
    @Override
    @AuditLog
    public DocumentStoredQueryResponse documentStoredQuery(DocumentStoredQuery message) {
        log.info("Executing operation documentStoredQuery:{}", Serializer.serialize(message));
        DocumentStoredQueryResponse response = queryDocumentSet(message);
        Asserts.nonNull(response, RhinAggrErrorType.DOCUMENT_STORED_QUERY_NOT_FOUND_FAULT);
        return response;
    }

    /**
     * 获取文档
     *
     * @param document
     * @return
     */
    private RetrieveDocumentSetResponse queryDocumentIndex(RetrieveDocumentSet document) {
        return wsClientFactory.getClient(DocumentStorage.class).retrieveDocumentSet(document);
    }

    /**
     * 索引文档
     *
     * @param query
     * @return
     */
    private DocumentStoredQueryResponse queryDocumentSet(DocumentStoredQuery query) {
        return wsClientFactory.getClient(DocumentManagement.class).documentStoredQuery(query);
    }

}
